﻿using Autofac.Extensions.DependencyInjection;
using Autofac;
using System.Reflection;
using System.Runtime.CompilerServices;

namespace Bird.OAWeb.WebAPI.Config
{
    public static  class AutofacConfig
    {
        public static void a(this IHostBuilder host)
        {
            host.UseServiceProviderFactory(new AutofacServiceProviderFactory());
            host.ConfigureContainer<ContainerBuilder>((context, builder) =>
            {
                //注入所有的Service
               builder.RegisterAssemblyTypes(Assembly.Load("Bird.OAWeb.Service"))
                .Where(a => a.Name.EndsWith("Service"))
                .AsImplementedInterfaces()
                .InstancePerLifetimeScope();

                //注入所有的仓储
                builder.RegisterAssemblyTypes(Assembly.Load("Bird.OAWeb.Ropesitory"))
                .Where(a => a.Name.EndsWith("Repository"))
                .AsImplementedInterfaces().InstancePerLifetimeScope();
                //注册所有泛型类
                builder.RegisterAssemblyOpenGenericTypes(Assembly.Load("Bird.OAWeb.Ropesitory"))
                .AsImplementedInterfaces()
                .InstancePerLifetimeScope();
            });
        }    }
}
